package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.BaseStudentDao;
import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.factory.StudentDaoFactory;

public class StudentService {
    private BaseStudentDao studentDao= StudentDaoFactory.getStudentDao();

    public boolean addStudent(Student student) {

        return studentDao.addStudenet(student);
    }

    public boolean isExists(String id) {
        Student[] stu = studentDao.findAllStudent();
        boolean flag = false;
        for (int i = 0; i < stu.length; i++) {
            if (stu[i] != null && stu[i].getId().equals(id)) {
                flag = true;
            }
        }
        return flag;
    }

    public Student[] findAllStudent() {
        Student[] stu = studentDao.findAllStudent();
        boolean flag = false;
        for (int i = 0; i < stu.length; i++) {
            if (stu[i] != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return stu;
        } else {
            return null;
        }

    }

    public void deleteStudent(String id) {
        studentDao.deleteStudent(id);
    }

    public void updateStudent(Student student, String id) {
        studentDao.updateStudent(student,id);
    }
}
